package com.kuaimacode.kframework.admin.services.finance;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kuaimacode.kframework.common.Constant;
import com.kuaimacode.kframework.mybatis.mapper.finance.AgentAccountDetailMapper;
import com.kuaimacode.kframework.mybatis.models.finance.AgentAccountDetail;
import com.kuaimacode.kframework.mybatis.models.finance.FinanceQuery;
import com.kuaimacode.kframework.mybatis.models.finance.FinanceTotal;
import com.kuaimacode.kframework.util.DateUtil;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author anzy
 * @date 2019/05/22
 */
@Service
public class  AgentAccountDetailService extends ServiceImpl<AgentAccountDetailMapper, AgentAccountDetail> {

    	/**
    	 *  分页查找所有的数据
    	 * @param pageNum 当前页码，从1开始
    	 * @param pageSize  一页显示多少行
    	 * @return
    	 */
    	public PageInfo<AgentAccountDetail> findSysAll(FinanceQuery query, int pageNum, int pageSize) {
    		PageHelper.startPage(pageNum, pageSize);
//    		QueryWrapper queryWrapper = new QueryWrapper();
//    		queryWrapper.eq("agent_id",Constant.DEFAULT_AGENT_ID);
//    		if(query.getStartDate()!=null) queryWrapper.ge("tran_time",query.getStartDate());
//    		if(query.getEndDate()!=null) queryWrapper.le("tran_time",query.getEndDate());
//    		List<AgentAccountDetail> datas = baseMapper.selectList(queryWrapper);
    		List<AgentAccountDetail> datas = baseMapper.queryPlantDetails(query);
    		return new PageInfo<AgentAccountDetail>(datas);
    	}

		/**
		 *  分页查找所有的数据
		 * @param pageNum 当前页码，从1开始
		 * @param pageSize  一页显示多少行
		 * @return
		 */
		public PageInfo<AgentAccountDetail> findAgentAll(FinanceQuery query,int pageNum, int pageSize) {
			PageHelper.startPage(pageNum, pageSize);
			QueryWrapper queryWrapper = new QueryWrapper();
			queryWrapper.ne("agent_id",Constant.DEFAULT_AGENT_ID);
			queryWrapper.eq("status","0");
//			if(query.getStartDate()!=null) queryWrapper.ge("tran_time", DateUtil.format(query.getStartDate(),"yyyy-MM-dd"));
//			if(query.getEndDate()!=null) queryWrapper.le("tran_time",DateUtil.format(query.getEndDate(),"yyyy-MM-dd"));
			List<AgentAccountDetail> datas = baseMapper.queryAgentDetails(query);
			return new PageInfo<AgentAccountDetail>(datas);
		}


		//查询平台合计金额
		public FinanceTotal querySysTotal(String agentId){

			return baseMapper.querySysTotal(agentId);

		}


    	//查询分站合计金额
    	public FinanceTotal queryAgentTotal(String agentId){

    		return baseMapper.queryAgentTotal(agentId);

		}


	/**
	 * 插入账户明细数据
	 */
	public long insertAgentAccountDetail(AgentAccountDetail accountDetail){
		accountDetail.setTranTime(new Date());
		baseMapper.insert(accountDetail);
		return accountDetail.getId();
	}

}

